During sequential and iterative program execution, processor memory references exhibit intense ◇spatial and ◇temporal locality:
Spatial Locality in Block Transfers: When an instruction fetch causes a cache miss, the memory controller fetches an entire block (B words) into cache. The first word incurs the full miss latency (tmiss), while the subsequent B−1 sequential words within that same block hit the cache (thit).
Temporal Locality in Looping Structures: When a program executes a loop of size L words, if the loop footprint fits within the cache without thrashing, only the first iteration incurs compulsory misses; all subsequent iterations achieve a 100% hit rate.
『』
TEXT
Memory Block (B words)
┌──────────┬──────────┬──────────┬──────────┬──────────┐
│ Word 0 │ Word 1 │ Word 2 │ ... │ Word B-1 │
└────┬─────┴────┬─────┴────┬─────┴──────────┴────┬─────┘
│ │ │ │
MISS HIT HIT HIT
(Fetch MM) (Cache) (Cache) (Cache)
2. Set Associativity & Working Set Thrashing
In a K-way set associative cache with S sets: Set Index=Block Number(modS)
Working Set Capacity: Each set can hold at most K distinct blocks concurrently.
Set Thrashing (The Pigeonhole Effect): If a tight loop references W distinct memory blocks that all map to the same set index, and W>K, then under ◇LRU replacement, every block access will cyclically evict the block needed next, reducing the cache hit rate to near zero despite available space in other sets.
3. Timing Models & Performance Equations
Memory Access Time Without Cache: Tno_cache=Nfetches×tmem
◇Problem 6: Set-Associative Execution Trace under Sequential Looping
Problem Statement
A system has a main memory consisting of 1 Mwords (220 words). It possesses a 4K-word cache (4096 words) organized in a block-set-associative manner with 4 blocks per set (K=4) and 64 words per block (B=64).
Total Main Memory Words: 220 words⟹Address Bits A=20 bits.
WORD Offset Field (w): w=log2(64 words/block)=6 bits
Total Cache Blocks: C=64 words/block4096 words=64 blocks
Total Cache Sets: S=4 blocks/set64 blocks=16 sets
SET Index Field (d): d=log2(16 sets)=4 bits
TAG Field (t): t=A−(d+w)=20−(4+6)=10 bits
TAG Field10 bits (Bits [19:10])SET Index Field4 bits (Bits [9:6])WORD Offset Field6 bits (Bits [5:0])
b. Total Instruction Fetch Time with NO Cache Memory
Sequence Parameters:
The processor fetches 4352 words from word addresses 0,1,2,…,4351 sequentially.
The sequence is repeated 9 more times, giving a total of: Total Iterations=1+9=10 iterations
Total Word Fetches: Ntotal words=4352 words/iteration×10 iterations=43,520 word fetches
Execution Time Without Cache:
Since every word fetch must be serviced directly from main memory at tmem=10 ns: Tno_cache=43,520×10 ns=435,200 ns=435.20μs
c. Cache Memory Performance with LRU Replacement
1. Working Set & Block Distribution Analysis
Total memory blocks spanned per iteration: Nblocks/iteration=64 words/block4352 words=68 blocks(Blocks 0 through 67)
Mapping function: Set Index=Block Number(mod16).
Distribution of the 68 blocks across the 16 cache sets: 68=(4×16)+4
Sets 0, 1, 2, and 3 receive 5 blocks each:
Set 0: Blocks {0,16,32,48,64}
Set 1: Blocks {1,17,33,49,65}
Set 2: Blocks {2,18,34,50,66}
Set 3: Blocks {3,19,35,51,67}
Sets 4 through 15 (12 sets) receive 4 blocks each:
Set 4: Blocks {4,20,36,52}
Set 5: Blocks {5,21,37,53}
…
Set 15: Blocks {15,31,47,63}
2. Iteration-by-Iteration Cache Behavior
A. Sets 4 through 15 (12 Sets × 4 Blocks = 48 Blocks)
Since each set capacity is K=4 blocks, all 4 blocks fit simultaneously in the set without eviction.
Iteration 1:
The 1st word of each block incurs a compulsory miss: 48 block misses (48 word misses).
The remaining 63 words in each block hit: 48×63=3,024 word hits.
Iterations 2 through 10 (9 iterations):
All 48 blocks remain resident in cache.
Block misses: 0
Block hits: 48×9=432 block hits
Word hits: 48×64 words×9=27,648 word hits
B. Sets 0 through 3 (4 Sets × 5 Blocks = 20 Blocks)
In each set, 5 blocks compete for 4 slots under LRU replacement:
Sequence in Set 0: Block 0 → Block 16 → Block 32 → Block 48 → Block 64.
Accessing Block 64 evicts the LRU block (Block 0).
In the subsequent iteration, when Block 0 is accessed, it misses and evicts Block 16.
When Block 16 is accessed, it misses and evicts Block 32, creating a cyclical thrashing loop.
Every Iteration (Iterations 1 through 10):
All 5 blocks in each of the 4 sets suffer a block miss on their first word access.
Block misses per iteration: 4 sets×5 blocks=20 block misses.
Block hits per iteration: 0 block hits.
Word fetches per iteration: 20 word misses (first word of each block) and 20×63=1,260 word hits.
Total across all 10 Iterations for Sets 0..3:
Total block misses: 20×10=200 block misses
Total block hits: 0 block hits
Total word misses: 200 word misses
Total word hits: 1,260×10=12,600 word hits
3. Aggregate Performance Metrics (across all 10 iterations)
Block-Level Access Metrics:
Total Block Accesses: Nblock accesses=68 blocks/iteration×10 iterations=680 block accesses
Total Block Accesses in Iter 1: 1+(20×2)+6=47 block accesses
Cache State at End of Outer Iteration 1: Line 0Block 8Line 1Block 9Line 2Block 2Line 3Block 3Line 4Block 4Line 5Block 5Line 6Block 6Line 7Block 7
Phase 3: Outer Loop Iterations 2 through 10 (9 Iterations)
In each of the remaining 9 iterations:
Access Block 1 (Line 1): Line 1 currently contains Block 9 ⟹Miss (Conflict). Line 1 is overwritten with Block 1.
Inner Loop (20 iterations of Blocks 2 and 3):
Blocks 2 and 3 are resident in Lines 2 and 3 and were never overwritten!
Total Block Misses: Nblock misses=1+9+18+2=30 block misses
Total Block Hits: Nblock hits=0+38+405+0=443 block hits
Block Hit Rate: Hblock=473443≈93.6575%
Block Miss Rate: Mblock=47330≈6.3425%
B. Word-Level Statistics
Total Word Fetches: Nwords=473 block accesses×128 words/block=60,544 words
Total Word Misses:
Each block miss results in exactly 1 word miss (the first word requested, which triggers the 128-word block refill): Nword misses=30 word misses
Total Word Hits: Nword hits=60,544−30=60,514 word hits (Composed of 443×128=56,704 hits from block hits + 30×127=3,810 hits from spatial locality within missed blocks)
Word Hit Rate: Hword=60,54460,514≈99.9504%
Word Miss Rate: Mword=60,54430≈0.0496%
C. Total Execution Time & Average Memory Access Time
Under the non-load-through policy (tcache=1 ns,tmem=10 ns⟹tmiss=11 ns): Ttotal=(60,514×1 ns)+(30×11 ns)=60,514+330=60,844 ns=60.844μs AMAT=60,54460,844 ns≈1.004955 ns≈1.0050 ns
Even when block hit rates are around 93.66%, the word hit rate exceeds 99.95% because a single 128-word block fetch provides 127 consecutive cache hits.
Increasing block size amortizes miss penalties across larger sequential instruction runs.
Conflict Miss Dynamics:
In Problem 7, the outer loop references 9 distinct blocks (Blocks 1 through 9) on an 8-line direct-mapped cache.
The conflict occurs strictly between Block 1 and Block 9, both mapping to Line 1.
If the cache were 2-way set associative with the same capacity (4 sets of 2 lines), Blocks 1 and 9 would coexist in Set 1 without eviction, eliminating all 18 conflict misses in iterations 2 through 10.
Compiler and Software Optimization Strategies:
Loop Alignment: Aligning loop entry points to cache line boundaries prevents loops from straddling unnecessary line boundaries.
Code Reordering / Loop Splitting: Restructuring code so that concurrent working sets do not alias to the same cache sets eliminates thrashing.